﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace mki.Backup.Objects
{
	public class ScheduleElement : CustomConfigurationElement
	{
		#region Enums (1)

		public enum Occurs
		{
			Daily,
			Weekly,
			Monthly
		}

		#endregion Enums

		#region Properties (5)

		/// <summary>
		/// Gets or sets the daily frequency.
		/// </summary>
		/// <value>
		/// The daily frequency.
		/// </value>
		[ConfigurationProperty("dailyFrequency", IsRequired = true)]
		public DailyFrequency DailyFrequency
		{
			get { return this["dailyFrequency"] as DailyFrequency; }
			set { this["dailyFrequency"] = value; }
		}

		/// <summary>
		/// Gets or sets the daily occurency.
		/// </summary>
		/// <value>
		/// The daily occurency.
		/// </value>
		[ConfigurationProperty("dailyOccurency")]
		public DailyOccurency DailyOccurency
		{
			get { return this["dailyOccurency"] as DailyOccurency; }
			set { this["dailyOccurency"] = value; }
		}

		/// <summary>
		/// Gets or sets the monthly occurency.
		/// </summary>
		/// <value>
		/// The monthly occurency.
		/// </value>
		[ConfigurationProperty("monthlyOccurency")]
		public MonthlyOccurency MonthlyOccurency
		{
			get { return this["monthlyOccurency"] as MonthlyOccurency; }
			set { this["monthlyOccurency"] = value; }
		}

		[ConfigurationProperty("occurrency", IsRequired = true)]
		public Occurs Occurrency
		{
			get { return (Occurs)this["occurrency"]; }
			set { this["occurrency"] = value; }
		}

		/// <summary>
		/// Gets or sets the weekly occurency.
		/// </summary>
		/// <value>
		/// The weekly occurency.
		/// </value>
		[ConfigurationProperty("weeklyOccurency")]
		public WeeklyOccurency WeeklyOccurency
		{
			get { return this["weeklyOccurency"] as WeeklyOccurency; }
			set { this["weeklyOccurency"] = value; }
		}

		#endregion Properties

		/// <summary>
		/// Gets a value indicating whether [start job].
		/// </summary>
		/// <value>
		///   <c>true</c> if [start job]; otherwise, <c>false</c>.
		/// </value>
		public Boolean StartJob
		{
			// ToDo: add logic to determine if job needs to get started
			get { return false; }
		}
	}

	public class DailyOccurency : CustomConfigurationElement
	{
		#region Properties (1)

		/// <summary>
		/// Gets or sets the frequency.
		/// </summary>
		/// <value>
		/// The frequency.
		/// </value>
		[ConfigurationProperty("frequency")]
		public Int32 Frequency
		{
			get { return Int32.Parse(this["frequency"].ToString()); }
			set { this["frequency"] = value; }
		}

		#endregion Properties
	}

	public class WeeklyOccurency : CustomConfigurationElement
	{
		#region Properties (8)

		/// <summary>
		/// Gets or sets the frequency.
		/// </summary>
		/// <value>
		/// The frequency.
		/// </value>
		[ConfigurationProperty("frequency")]
		public Int32 Frequency
		{
			get { return Int32.Parse(this["frequency"].ToString()); }
			set { this["frequency"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="WeeklyOccurency"/> is friday.
		/// </summary>
		/// <value>
		///   <c>true</c> if friday; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("friday")]
		public Boolean Friday
		{
			get { return Boolean.Parse(this["friday"].ToString()); }
			set { this["friday"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="WeeklyOccurency"/> is monday.
		/// </summary>
		/// <value>
		///   <c>true</c> if monday; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("monday")]
		public Boolean Monday
		{
			get { return Boolean.Parse(this["monday"].ToString()); }
			set { this["monday"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="WeeklyOccurency"/> is saturday.
		/// </summary>
		/// <value>
		///   <c>true</c> if saturday; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("saturday")]
		public Boolean Saturday
		{
			get { return Boolean.Parse(this["saturday"].ToString()); }
			set { this["saturday"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="WeeklyOccurency"/> is sunday.
		/// </summary>
		/// <value>
		///   <c>true</c> if sunday; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("sunday")]
		public Boolean Sunday
		{
			get { return Boolean.Parse(this["sunday"].ToString()); }
			set { this["sunday"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="WeeklyOccurency"/> is thuesday.
		/// </summary>
		/// <value>
		///   <c>true</c> if thuesday; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("thuesday")]
		public Boolean Thuesday
		{
			get { return Boolean.Parse(this["thuesday"].ToString()); }
			set { this["thuesday"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="WeeklyOccurency"/> is thursday.
		/// </summary>
		/// <value>
		///   <c>true</c> if thursday; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("thursday")]
		public Boolean Thursday
		{
			get { return Boolean.Parse(this["thursday"].ToString()); }
			set { this["thursday"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="WeeklyOccurency"/> is wednesday.
		/// </summary>
		/// <value>
		///   <c>true</c> if wednesday; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("wednesday")]
		public Boolean Wednesday
		{
			get { return Boolean.Parse(this["wednesday"].ToString()); }
			set { this["wednesday"] = value; }
		}

		#endregion Properties
	}

	public class MonthlyOccurency : CustomConfigurationElement
	{
		#region Properties (2)

		/// <summary>
		/// Gets or sets the monthly custom frequency.
		/// </summary>
		/// <value>
		/// The monthly custom frequency.
		/// </value>
		[ConfigurationProperty("monthlyCustomFrequency")]
		public MonthlyCustomFrequency MonthlyCustomFrequency
		{
			get { return this["monthlyCustomFrequency"] as MonthlyCustomFrequency; }
			set { this["monthlyCustomFrequency"] = value; }
		}

		/// <summary>
		/// Gets or sets the monthly day frequency.
		/// </summary>
		/// <value>
		/// The monthly day frequency.
		/// </value>
		[ConfigurationProperty("monthlyDayFrequency")]
		public MonthlyDayFrequency MonthlyDayFrequency
		{
			get { return this["monthlyDayFrequency"] as MonthlyDayFrequency; }
			set { this["monthlyDayFrequency"] = value; }
		}

		#endregion Properties
	}

	public class MonthlyDayFrequency : CustomConfigurationElement
	{
		#region Properties (2)

		/// <summary>
		/// Gets or sets the day frequency.
		/// </summary>
		/// <value>
		/// The day frequency.
		/// </value>
		[ConfigurationProperty("dayFrequency")]
		public Int32 DayFrequency
		{
			get { return Int32.Parse(this["dayFrequency"].ToString()); }
			set { this["dayFrequency"] = value; }
		}

		/// <summary>
		/// Gets or sets the month frequency.
		/// </summary>
		/// <value>
		/// The month frequency.
		/// </value>
		[ConfigurationProperty("monthFrequency")]
		public Int32 MonthFrequency
		{
			get { return Int32.Parse(this["monthFrequency"].ToString()); }
			set { this["monthFrequency"] = value; }
		}

		#endregion Properties
	}

	public class MonthlyCustomFrequency : CustomConfigurationElement
	{
		#region Enums (1)

		public enum WeekOccurency
		{
			First,
			Second,
			Third,
			Fourth,
			Fifth
		}

		#endregion Enums

		#region Properties (3)

		/// <summary>
		/// Gets or sets the month frequency.
		/// </summary>
		/// <value>
		/// The month frequency.
		/// </value>
		[ConfigurationProperty("monthFrequency")]
		public Int32 MonthFrequency
		{
			get { return Int32.Parse(this["monthFrequency"].ToString()); }
			set { this["monthFrequency"] = value; }
		}

		/// <summary>
		/// Gets or sets the occurency.
		/// </summary>
		/// <value>
		/// The occurency.
		/// </value>
		[ConfigurationProperty("occurency")]
		public WeekOccurency Occurency
		{
			get { return (WeekOccurency)this["occurency"]; }
			set { this["occurency"] = value; }
		}

		/// <summary>
		/// Gets or sets the weekday.
		/// </summary>
		/// <value>
		/// The weekday.
		/// </value>
		[ConfigurationProperty("weekday")]
		public DayOfWeek Weekday
		{
			get { return (DayOfWeek)this["weekday"]; }
			set { this["weekday"] = value; }
		}

		#endregion Properties
	}

	public class DailyFrequency : CustomConfigurationElement
	{
		#region Properties (2)

		/// <summary>
		/// Gets or sets the daily frequency.
		/// </summary>
		/// <value>
		/// The daily frequency.
		/// </value>
		[ConfigurationProperty("dailyFrequency")]
		public DailyFrequencyPeriodic DailyFrequence
		{
			get { return this["dailyFrequency"] as DailyFrequencyPeriodic; }
			set { this["dailyFrequency"] = value; }
		}

		/// <summary>
		/// Gets or sets the daily frequency once.
		/// </summary>
		/// <value>
		/// The daily frequency once.
		/// </value>
		[ConfigurationProperty("dailyFrequencyOnce")]
		public DailyFrequencyOnce DailyFrequencyOnce
		{
			get { return this["dailyFrequencyOnce"] as DailyFrequencyOnce; }
			set { this["dailyFrequencyOnce"] = value; }
		}

		#endregion Properties
	}

	public class DailyFrequencyOnce : CustomConfigurationElement
	{
		#region Properties (1)

		/// <summary>
		/// Gets or sets the occurs once at.
		/// </summary>
		/// <value>
		/// The occurs once at.
		/// </value>
		[ConfigurationProperty("occursOnceAt", IsRequired = true)]
		public String OccursOnceAt
		{
			get { return this["occursOnceAt"].ToString(); }
			set { this["occursOnceAt"] = value; }
		}

		#endregion Properties
	}

	public class DailyFrequencyPeriodic : CustomConfigurationElement
	{
		#region Enums (1)

		public enum Frequency
		{
			Minute,
			Hour
		}

		#endregion Enums

		#region Properties (4)

		/// <summary>
		/// Gets or sets the ending at.
		/// </summary>
		/// <value>
		/// The ending at.
		/// </value>
		[ConfigurationProperty("endingAt")]
		public DateTime EndingAt
		{
			get { return DateTime.Parse(this["endingAt"].ToString()); }
			set { this["endingAt"] = value; }
		}

		/// <summary>
		/// Gets or sets the frequency.
		/// </summary>
		/// <value>
		/// The frequency.
		/// </value>
		[ConfigurationProperty("frequency", IsRequired = true)]
		public Frequency Frequence
		{
			get { return (Frequency)this["frequency"]; }
			set { this["frequency"] = value; }
		}

		/// <summary>
		/// Gets or sets the occurs every.
		/// </summary>
		/// <value>
		/// The occurs every.
		/// </value>
		[ConfigurationProperty("occursEvery", IsRequired = true)]
		public Byte OccursEvery
		{
			get { return Byte.Parse(this["occursEvery"].ToString()); }
			set { this["occursEvery"] = value; }
		}

		/// <summary>
		/// Gets or sets the starting at.
		/// </summary>
		/// <value>
		/// The starting at.
		/// </value>
		[ConfigurationProperty("startingAt")]
		public DateTime StartingAt
		{
			get { return DateTime.Parse(this["startingAt"].ToString()); }
			set { this["startingAt"] = value; }
		}

		#endregion Properties
	}
}